package com.example.smartmallserver.demos.web.mapper;

import com.example.smartmallserver.demos.web.pojo.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface IndexMapper {

    @Select("select * from smartmail.carouselimages")
    List<CarouselImage> getCarouselImages();

    @Select("select * from smartmail.navigation")
    List<Navigation> getNavigations();

    @Select("select * from smartmail.goods")
    List<Goods> getGoods();

    @Select("SELECT * FROM smartmail.goods WHERE name LIKE CONCAT('%', #{name}, '%')")
    List<Goods> getGoodsByName(String name);

    @Select("select * from smartmail.goods where goods_kind=${categoryId}")
    List<Goods> getGoodsByCategoryId(Integer categoryId);

    @Select("select * from smartmail.goods where id=${goodsId}")
    Goods getGoodsById(Integer goodsId);

    @Select("select * from smartmail.comment where goods_id=${goodsId}")
    List<Comment> getCommentByGoodsById(Integer goodsId);

    @Update("UPDATE smartmail.cart SET goodsNum = goodsNum + #{goodsNum} WHERE userId = #{userId} AND goodsId = #{goodsId}")
    void updateCart(Cart cart);

    @Select("select * from smartmail.cart where goodsId=${goodsId} and userId=${userId}")
    List<Cart> selectCart(Cart cart);

    @Insert("insert into smartmail.cart (userId, goodsId, goodsName, goodsPrice, goodsNum, goodsImage) " +
            "values (${userId},${goodsId},'${goodsName}',${goodsPrice},${goodsNum},'${goodsImage}')")
    void addCart(Cart cart);

    @Select("select sum(goodsNum) from smartmail.cart where userId=${id}")
    Integer getCartCountById(Object id);

    @Select("select * from smartmail.cart where userId=${id}")
    List<Cart> getCartList(Object id);

    @Update("UPDATE smartmail.cart SET goodsNum = #{goodsNum} WHERE id = #{id}")
    void updadeCartCount(Cart cart);

    @Delete("delete from smartmail.cart where id = #{id}")
    void deleteCartById(Integer id);

    @Select("select * from smartmail.address where userId=${id}")
    List<Address> getAddressList(Object id);

    @Select("select * from smartmail.cart where id=${cartId}")
    Cart checkOrder(Integer cartId);

    @Select("select * from smartmail.user where id=${id}")
    User getUserById(Object id);

    @Select("select * from smartmail.orderitem where orderId=${orderId} and status='${status}'")
    List<OrderItem> getOrderListByStatus(@Param("status") String status, @Param("orderId") Integer orderId);

    @Select("select * from smartmail.orderitem where orderId=${orderId}")
    List<OrderItem> getOrderListAll(Integer orderId);

    @Select("select * from smartmail.orderid where userId=${userId}")
    List<OrderId> getOrderIds(Integer userId);
}
